import requests
import os

# 图片的URL地址
url = "http://n.sinaimg.cn/news/crawl/117/w550h367/20220417/a3a9-08b2ca6dffe4210149dda424adf0734f.jpg"
# 将图片保存到桌面上
save_path = os.path.join("C:/Users/小华/Desktop", "image.jpg")
# 用get请求
response = requests.get(url, stream=True)
# 检查请求是否成功
response.raise_for_status()
# 以二进制写入模式保存图片
with open(save_path, "wb") as file:
    for chunk in response.iter_content(1024):
        file.write(chunk)
print("图片保存成功")
